home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / screen_1 / scrnres.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1996-12-27  |  3.0 KB  |  94 lines

  1. VERSION 4.00
  2. Begin VB.Form Form1 
  3.    BorderStyle     =   3  'Fixed Dialog
  4.    Caption         =   "Screen Resolution"
  5.    ClientHeight    =   525
  6.    ClientLeft      =   2475
  7.    ClientTop       =   3015
  8.    ClientWidth     =   4170
  9.    Height          =   930
  10.    Left            =   2415
  11.    LinkTopic       =   "Form1"
  12.    MaxButton       =   0   'False
  13.    MinButton       =   0   'False
  14.    ScaleHeight     =   525
  15.    ScaleWidth      =   4170
  16.    ShowInTaskbar   =   0   'False
  17.    Top             =   2670
  18.    Width           =   4290
  19.    Begin VB.Label Label2 
  20.       Caption         =   "Label2"
  21.       Height          =   255
  22.       Left            =   2040
  23.       TabIndex        =   1
  24.       Top             =   120
  25.       Width           =   1935
  26.    End
  27.    Begin VB.Label Label1 
  28.       Caption         =   "Your screen resolution is"
  29.       Height          =   255
  30.       Left            =   120
  31.       TabIndex        =   0
  32.       Top             =   120
  33.       Width           =   1815
  34.    End
  35. Attribute VB_Name = "Form1"
  36. Attribute VB_Creatable = False
  37. Attribute VB_Exposed = False
  38. Option Explicit
  39. 'API Declares.
  40. '*************************************************
  41. 'Gets window handle for Desktop window.
  42. Private Declare Function GetDesktopWindow Lib "User32" () As Long
  43. 'Retrieve device context.
  44. Private Declare Function GetDC Lib "User32" (ByVal hwnd As Long) As Long
  45. 'Get device capabilities.
  46. Private Declare Function GetDeviceCaps Lib "gdi32" (ByVal hdc As Long, ByVal nIndex As Long) As Long
  47. 'Release device context.
  48. Private Declare Function ReleaseDC Lib "User32" (ByVal hwnd As Long, ByVal hdc As Long) As Long
  49. Public Sub DesktopHandle()
  50.     Dim hdesktopwnd
  51.     'Get handle to Desktop.
  52.     hdesktopwnd = GetDesktopWindow()
  53. End Sub
  54. Public Sub DeviceInfo()
  55.     Dim DisplayBits
  56.     Dim DisplayPlanes
  57.     Dim DisplayWidth
  58.     Dim DisplayHeight
  59.     Dim RetVal
  60.    'Get display context for desktop.
  61.     hdccaps = GetDC(hdesktopwnd)
  62.     'Bits per pixel.
  63.     DisplayBits = GetDeviceCaps(hdccaps, 12)
  64.     'Bitplanes.
  65.     DisplayPlanes = GetDeviceCaps(hdccaps, 14)
  66.     'Horz. Resolution.
  67.     DisplayWidth = GetDeviceCaps(hdccaps, 8)
  68.     'Vert. Resolution.
  69.     DisplayHeight = GetDeviceCaps(hdccaps, 10)
  70.     'Release display context.
  71.     RetVal = ReleaseDC(hdesktopwnd, hdccaps)
  72.     'To determine colors:
  73. If DisplayBits = 1 Then
  74. If DisplayPlanes = 1 Then
  75.     'Running in 1-bit, 2 color mode.
  76.     Label2 = "1-bit/2 colours"
  77. ElseIf DisplayPlanes = 4 Then
  78.     'Running in 4-bit, 16 color mode.
  79.     Label2 = "4-bit/16 colur mode"
  80. End If
  81. ElseIf DisplayBits = 8 Then
  82.     'Running in 8-bit, 256 color mode.
  83.     Label2 = "8 bit/256 colours"
  84. ElseIf DisplayBits = 16 Then
  85.     'Running in 16-bit, 65000 color mode.
  86.     Label2 = "16 bit/65,000 colours"
  87.     'Running in custom color mode (16million).
  88.     Label2 = "Hmmmm...could be 16,000,000 colurs, or Custom Mode"
  89. End If
  90. End Sub
  91. Private Sub Form_Load()
  92. Call DeviceInfo
  93. End Sub
  94.